package org.hong.monkey.crawl

import java.util.concurrent.Executors
import org.hong.monkey.util.Utils
import scala.concurrent.ExecutionContext

/**
 * Created by wangsihong on 2016/10/31.
 */

abstract class HttpDownloader {
  def get(crawlRequest: CrawlRequest)(implicit executor: ExecutionContext) : CrawlResponse
}

private object HttpDownloader {
  val executor = ExecutionContext.fromExecutorService(Executors.newCachedThreadPool())

  def main(args: Array[String]) {

    WebkitUtils.connect("10.58.222.104:2181")

    val request = CrawlRequest("http://www.baidu.com",
      downloaderClass = "org.hong.monkey.crawl.WebkitDownloader",
      spiderkitGroup = "DynamicIp")
    println(request.downloaderClass)

    val downloader = Utils.classForName(request.downloaderClass)
      .getConstructor().newInstance().asInstanceOf[HttpDownloader]

    val response = downloader.get(request)(executor)

    println(response.toString() + "|" + response.cookies)

  }
}

